package org.edith.shiro.util;

import org.edith.shiro.dataobject.SysUserDO;
import org.apache.commons.lang3.RandomStringUtils;

/**
 * 用户密码加密工具类
 */
public class UserPasswordUtils {
    /**
     * 加密用户密码
     * @param sysUserDO
     * @return
     */
    public static SysUserDO encrypt(SysUserDO sysUserDO){
        // 随机生成盐值
        String salt = RandomStringUtils.randomAlphanumeric(20);
        sysUserDO.setSalt(salt);
        sysUserDO.setPassword(SHA256Util.sha256(sysUserDO.getPassword(), salt));
        return sysUserDO;
    }
}
